/**
 * 
 */
package com.scaffold.springmvc.action;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

import com.scaffold.BasicBizAction;
import com.scaffold.commons.web.WebUtil;

/**
 * @author wangjg
 *
 */
@Controller
public class CommonJsonAction extends BasicBizAction{

	@RequestMapping("/common/echo.json")
	public String echo(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("params", this.getParameterMap());
		map.put("heads", WebUtil.getHeaders(this.getRequest()).toString());
		return this.getSuccessResult(map);
	}
	
	@RequestMapping("/common/serverInfo.json")
	public String serverInfo(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("time", ""+System.currentTimeMillis());
		map.put("System properties", getSysProperties(true));
		return this.getResult("0000", "", map);
	}
	
	private Map getSysProperties(boolean filter){
		Map<String, Object> map = new HashMap<String, Object>();
		Properties pp = System.getProperties();
		Set<Entry<Object, Object>> entrySet = pp.entrySet();
		for(Entry<Object, Object> etnry:entrySet){
			String key = ""+etnry.getKey();
			String value = ""+etnry.getValue();
			if(key.indexOf("rjr")!=-1){
				continue;
			}
			if(key.indexOf("path")!=-1){
				continue;
			}
			if(key.indexOf("dir")!=-1){
				continue;
			}
			if(key.indexOf("home")!=-1){
				continue;
			}
			if(key.indexOf("key")!=-1){
				continue;
			}
			if(key.indexOf("password")!=-1){
				continue;
			}
			if(key.indexOf("home")!=-1){
				continue;
			}
			if(key.indexOf("file")!=-1){
				continue;
			}
			if(key.indexOf("base")!=-1){
				continue;
			}
			if(key.indexOf("user")!=-1){
				continue;
			}
			map.put(key, value);
		}
		return map;
	}

	@ResponseBody
	@RequestMapping("/common/quotes.json")
	public DeferredResult quotes() {
	  DeferredResult deferredResult = new DeferredResult();
	  return deferredResult;
	}
	
}
